package com.dayaokeji.rhythmschoolstudent.client.common.questions_and_answers;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.ApiConstantKt;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUrlModel;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUtils;
import com.dayaokeji.rhythmschoolstudent.utils.FileUtil;
import com.dayaokeji.server_api.domain.FileInfo;

/**
 * Created by Gorden on 2017/11/16.
 */

public class QuestionAndAnswersAdapter extends BaseQuickAdapter<FileInfo,BaseViewHolder> {


    private final RequestOptions requestOptions;

    public QuestionAndAnswersAdapter() {
        super(R.layout.item_question_answers, null);
        requestOptions = new RequestOptions();
        requestOptions.placeholder(R.mipmap.img_default);
        requestOptions.error(R.mipmap.img_default);
        requestOptions.error(R.mipmap.img_default);
        requestOptions.fallback(R.mipmap.img_default);
    }

    @Override
    protected void convert(BaseViewHolder helper, FileInfo item) {
        helper.addOnClickListener(R.id.tv_download_file);
        GlideUtils.with(mContext).applyDefaultRequestOptions(requestOptions).load(new GlideUrlModel(ApiConstantKt.getRemoteImageUrl()+item.getId())).into((ImageView) helper.getView(R.id.iv_preview));
        helper.setText(R.id.tv_image_name,item.getName());
        TextView tvDownloadFile = (TextView) helper.getView(R.id.tv_download_file);
        tvDownloadFile.setEnabled(!FileUtil.isFileExists(item.getName()));
    }
}
